package com.flejay.dreamrecruiter.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * Classe abstraite non instanciable qui représente un bloc de données du CV
 * 
 * @author Victor Fleurant
 *
 */
public class AbstractBlock {

	protected AbstractBlock(){
		super();
	}
	
	public static AbstractBlock getNewInstance(){
		AbstractBlock block = new AbstractBlock();
		block.setContent(new StringBuffer());
		block.setAssociatedTag(null);
		return block;
	}
	
	// contenu du bloc
	private StringBuffer content;
	// mot clef associé au bloc
	private AbstractTag associatedTag;
	// le bloc n'est pas trop gros par defaut
	private boolean overSized = false;
	
	public StringBuffer getContent() {
		return content;
	}

	public void setContent(final StringBuffer content) {
		this.content = content;
	}

	public String getStringContent() {
		return (content != null) ? content.toString() : "";
	}
	
	public AbstractTag getAssociatedTag() {
		return associatedTag;
	}

	public void setAssociatedTag(final AbstractTag associatedTag) {
		this.associatedTag = associatedTag;
	}

	public boolean isOverSized() {
		return overSized;
	}

	public void setOverSized(boolean overSized) {
		this.overSized = overSized;
	}

	/**
	 * Cast a list of AbstractBlock into a List of Block
	 * @param aBlockList
	 * @return
	 */
	public static List<Block> toBlockList(final List<AbstractBlock> aBlockList){
		List<Block> blockRes = new ArrayList<Block>();
		for(AbstractBlock block : aBlockList){
			blockRes.add((Block)block);
		}
		return blockRes;
	}
	
	/**
	 * Cast a list of AbstractBlock into a List of SubBlock
	 * @param aBlockList
	 * @return
	 */
	public static List<SubBlock> toSubBlockList(final List<AbstractBlock> aBlockList){
		List<SubBlock> blockRes = new ArrayList<SubBlock>();
		for(AbstractBlock block : aBlockList){
			blockRes.add((SubBlock)block);
		}
		return blockRes;
	}
	
	/**
	 * Cast a list of AbstractBlock into a List of Block
	 * @param aBlockList
	 * @return
	 */
	public static List<AbstractBlock> toAbstractBlockList(final List<Block> aBlockList){
		List<AbstractBlock> blockRes = new ArrayList<AbstractBlock>();
		for(Block block : aBlockList){
			blockRes.add((AbstractBlock)block);
		}
		return blockRes;
	}
	
	@Override
	public String toString(){
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
